package com.taomu.app.zongchouhuli.moudle.mine.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.framework.BaseActivity;
import com.taomu.app.zongchouhuli.framework.BasePresenter;
import com.taomu.app.zongchouhuli.moudle.login.activity.LoginActivity;
import com.taomu.app.zongchouhuli.utils.GlideCacheUtil;
import com.taomu.app.zongchouhuli.utils.StorageHelper;
import com.taomu.app.zongchouhuli.weight.LineViewText;

public class UserSettingAcitivity extends BaseActivity {

    private ImageView mBackIm;

    private LineViewText mSafeLvt;

    private LineViewText mCacheLvt;

    private TextView mLogoutTv;

    private TextView mCopyRightTv;

    @Override
    protected void onResume() {
        if(!TextUtils.isEmpty(StorageHelper.getToken())){
            mLogoutTv.setVisibility(View.VISIBLE);
        }else{
            mLogoutTv.setVisibility(View.INVISIBLE);
        }
        super.onResume();
    }

    @Override
    protected int getContentLayout() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {
        mBackIm = findViewById(R.id.set_back_im);
        mSafeLvt = findViewById(R.id.set_safe_lvt);
        mCacheLvt = findViewById(R.id.set_cache_lvt);
        mLogoutTv = findViewById(R.id.set_logout_tv);
        mCopyRightTv = findViewById(R.id.set_copyright_tv);
    }

    @Override
    protected void initData() {
        mCacheLvt.setText(GlideCacheUtil.getInstance().getCacheSize(getApplicationContext()));

    }

    @Override
    protected void initEvent() {
        mBackIm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mLogoutTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StorageHelper.removeToken();
                StorageHelper.removeUid();
                Log.d("dwqdqwdwqdwq", "toekn:"+StorageHelper.getToken());
                showToast("已退出登录");
                mLogoutTv.setVisibility(View.GONE);
                Intent intent = new Intent(UserSettingAcitivity.this,LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
        mSafeLvt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(StorageHelper.isLogin()) {
                    startActivity(UserSafeActivity.class);
                }else{
                    Intent intent = new Intent(UserSettingAcitivity.this,LoginActivity.class);
                    startActivity(intent);
                }
            }
        });
        mCacheLvt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //todo:清除缓存
                if(mCacheLvt.getText().toString().contains("0.00")){
                    showToast("当前无需清理缓存");
                }else{
                    GlideCacheUtil.getInstance().clearImageAllCache(getApplicationContext());
                    mCacheLvt.setText("0.00Byte");
                    showToast("已经清理完成");
                }
            }
        });
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }
}
